-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[client] Fix prioritization of requested Oauth scopes #1324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[client] Fix prioritization of requested Oauth scopes #1324
Conversation
Can we confirm if updating the Python SDK will update the Claude Client, or will we also need to make updates in the TypeScript SDK for these to reflect in Claude.ai? In the Typescript SDK, for example, we are not retrieving scopes from the PRM endpoint: https://github.com/modelcontextprotocol/typescript-sdk/blob/main/src/client/auth.ts#L328 |
elif metadata.scopes_supported is not None: | ||
self.context.client_metadata.scope = " ".join(metadata.scopes_supported) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see this latest change to the spec:
When implementing authorization flows, MCP clients SHOULD follow the principle of least privilege by requesting
only the scopes necessary for their intended operations. During the initial authorization handshake, MCP clients
SHOULD follow this priority order for scope selection:
- Use
scope
parameter from the initialWWW-Authenticate
header in the 401 response, if provided- If
scope
is not available, use all scopes defined inscopes_supported
from the Protected Resource Metadata document, omitting thescope
parameter ifscopes_supported
is undefined.This approach accommodates the general-purpose nature of MCP clients, which typically lack domain-specific knowledge to make informed decisions about individual scope selection. Requesting all available scopes allows the authorization server and end-user to determine appropriate permissions during the consent process.
Are you able to update this PR to:
- Get scope from
www-authenticate
- Omit scope if not present in PRM? (currently impl falls back to
scopes_supported
from AS metadata)
Fix OAuth scope handling to prioritize PRM spec's
scopes_supported
over Authorization Server Metadata spec'sscopes_supported
, ensuring clients only request resource-specific scopes and preventing authorization rejections in multi-resource environments.Motivation and Context
Currently, the MCP client prioritizes all scopes from the OAuth authorization server metadata endpoint, which can cause issues in multi-resource environments. This update reverses the priority order: it first checks the Protected Resource Metadata (PRM) endpoint's
scopes_supported
field to obtain only the necessary scopes for the specific resource, and only falls back to the authorization server metadata if needed.This addresses issues such as:
"resource1:read"
and"resource2:read"
).How Has This Been Tested?
Comprehensive test cases were added in
tests/client/test_auth.py
to cover various scope handling scenarios:Breaking Changes
This is a breaking change for applications relying on the previous scope handling behavior. The new implementation aligns with the PRM specification, which states that
scopes_supported
contains "scope values that are used in authorization requests to request access to this protected resource."Types of Changes
Checklist
Additional Context
The core change modifies the
_handle_oauth_metadata_response
method insrc/mcp/client/auth.py
to properly prioritize scopes from PRM over OAuth metadata. This ensures clients only request scopes relevant to the specific resource, improving security and reducing authorization rejections.